<?php

class eventoActions extends sfActions {

    public function preExecute()
    {
         $this->getUser()->setAttribute('s_menu', 'evento');
    }

       public function executeVeri(sfWebRequest $request){
           $c=new Criteria();
           $c->add(NoticiasPeer::ID_CAT,1);
           $c->add(NoticiasPeer::DATE, date("Y-m-d"), Criteria::GREATER_EQUAL);
           $cont=NoticiasPeer::doCount($c);
               if($cont>0 ){

                    $this->redirect('@evento_active');
               }
               else{
                    $this->redirect('@evento_past');
               }
       }


    
    public function executeActive(sfWebRequest $request){
        $c = new Criteria();
        $events = array();

        $c->clear();
        $c->add(NoticiasPeer::DATE, date("Y-m-d"), Criteria::GREATER_EQUAL);
        $c->add(NoticiasPeer::ENABLED, 1);
        $c->add(NoticiasPeer::ID_CAT, 1);
        $c->addAscendingOrderByColumn(NoticiasPeer::DATE);

 

        
        $pager = new sfPropelPager('Noticias', 14);
        $pager->setCriteria($c);
        $pager->setPage($request->getParameter('page', 1));
        $pager->init();
        $this->pager = $pager;

        $maxpag=$pager->getMaxPerPage();
        $this->max=$maxpag;
        $pagina=$request->getParameter('page',1);
        $this->pagina=$pagina;
    
 
    }



    public function executePast(sfWebRequest $request){
        $c = new Criteria();
        $events = array();

  

        $c->clear();
        $c->add(NoticiasPeer::DATE, date("Y-m-d"), Criteria::LESS_THAN);
        $c->add(NoticiasPeer::ENABLED, 1);
        $c->add(NoticiasPeer::ID_CAT, 1);
        $c->addAscendingOrderByColumn(NoticiasPeer::DATE);

        /*el segundo parametro es el numero maximo de paginacion (cantidad de paginacion)*/
        $pager = new sfPropelPager('Noticias',14);
        $pager->setCriteria($c);
        /*el numero de la pagina al incio */
        $pager->setPage($request->getParameter('page', 1));
        $pager->init();
        $this->pager = $pager;

        $maxpag=$pager->getMaxPerPage();
        $this->max=$maxpag;
        $pagina=$request->getParameter('page',1);
        $this->pagina=$pagina;
    }

    public function executeDetail(sfWebRequest $request){
        $event = null;
        $id = $request->getParameter('id');

        $c = new Criteria();
        $c->add(NoticiasPeer::ID, $id);
        $c->add(NoticiasPeer::ENABLED, 1);
        $event = NoticiasPeer::doSelectOne($c);
        if(!is_object($event)){
            $this->forward404();
        }

        $this->event = $event;
    }

}